﻿@model ZdSoft.Model.Resource

@{
    Layout = null;
    var isActive = new List<SelectListItem>() {
            new SelectListItem() { Value = "资源上架", Text = "资源上架" },
            new SelectListItem() { Value = "资源下架", Text = "资源下架" }
        };
    var resourcesType = new List<SelectListItem>() {
            new SelectListItem() { Value ="1", Text = "视频" },
            new SelectListItem() { Value = "2", Text = "音频" } ,
            new SelectListItem() { Value = "3", Text = "PPT" }  ,
            new SelectListItem() { Value = "4", Text = "Word" }  ,
            new SelectListItem() { Value = "5", Text = "Txt" },
            new SelectListItem() { Value = "6", Text = "其他" }

        };
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>创建课件信息</title>
    <link href="~/Content/layer.css" rel="stylesheet" />
    <link href="~/Content/layui.css" rel="stylesheet" />
    <style>
        .layui-form-item {
            margin-top: 12px;
        }

            .layui-form-item .layui-input-block {
                margin-top: 8px;
            }

        #createSourse {
            margin: 12px;
        }
    </style>

</head>
<body>
    @using (Html.BeginForm("Create", "Resource", FormMethod.Post, new { enctype = "multipart/form-data", id = "createSourse", name = "createSourse", @class = "layui-form" }))
    {
        @Html.AntiForgeryToken()
    <h3 style="text-align:center;margin-top:10px">创建课件信息</h3>
    <hr />
        <div class="layui-form-item">
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <div class="layui-form-item">
                @Html.LabelFor(model => model.ResourcesName, htmlAttributes: new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.EditorFor(model => model.ResourcesName, new { htmlAttributes = new { @placeholder = "ResourcesName", @autocomplete = "off", @class = "layui-input" } })
                    @Html.ValidationMessageFor(model => model.ResourcesName, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.ResourcesUrl, htmlAttributes: new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    <input type="file" name="ResourcesUrl" id="ResourcesUrl" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                @Html.LabelFor(model => model.ResourcesType, htmlAttributes: new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.DropDownListFor(model => model.ResourcesType, resourcesType as IEnumerable<SelectListItem>, new { htmlAttributes = new { @placeholder = "ResourcesType", @autocomplete = "off", @class = "layui-input" } })
                    @Html.ValidationMessageFor(model => model.ResourcesType, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.ResourcesInfo, htmlAttributes: new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.TextAreaFor(model => model.ResourcesInfo, new { @placeholder = "ResourcesInfo", @autocomplete = "off", @class = "layui-input" })
                    @Html.ValidationMessageFor(model => model.ResourcesInfo, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="layui-form-item">
                @Html.LabelFor(model => model.IsActive, htmlAttributes: new { @class = "layui-form-label" })
                <div class="layui-input-block">
                    @Html.DropDownListFor(model => model.IsActive, isActive as IEnumerable<SelectListItem>, new { htmlAttributes = new { @placeholder = "IsActive", @autocomplete = "off", @class = "layui-input" } })
                    @Html.ValidationMessageFor(model => model.IsActive, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="layui-form-item">
                <div class="col-md-offset-2 layui-input-block">
                    <input type="button" value="取消" class="layui-btn" id="exit" />
                    <input type="submit" value="确认创建" name="createAll" id="fileSend" class="layui-btn" />
                </div>
            </div>
        </div>
    }
</body>
</html>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.form.js"></script>
<script src="~/Scripts/layui.js"></script>
<script>   
    (function () {
        $('#createSourse').ajaxForm({
            beforeSend: function () {
                $("#fileSend").attr({ value: "创建中...", disabled: "disabled" }).css("background", "#666");
            },
            success: function (data) {
                if (data.status == "success")
                {
                    //$("#ResourcesUrl").val(data.filePath);
                    layer.msg("创建课件成功");
                    $("#fileSend").removeAttr("disabled").attr({ value: "确认创建" }).css("background", "#009688");
                }
                else {
                    layer.msg("创建课件失败");
                    $("#fileSend").removeAttr("disabled").attr({ value: "确认创建" }).css("background", "#009688");
                }
            },
            error:function(){
                layer.msg("创建课件失败");
                $("#fileSend").removeAttr("disabled").attr({ value: "确认创建" }).css("background", "#009688");
            },
            complete: function (xhr) {
               
            }
        });

    })();
    $(function () {
        $("#ResourcesInfo").css("display", "none");
        layui.use('layedit', function () {
            var layedit = layui.layedit;
            layedit.build('ResourcesInfo'); //建立编辑器
        });
        //退出创建课程信息
        $("#exit").click(function () {
            parent.layer.closeAll();
        });
    });
</script>